package com.study.security.web.aspect;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.stereotype.Component;

@Aspect
@Component
public class MyAspect {

//    @Before()
//    @After()
//    @AfterThrowing
//    @Around()

    /**
     * @param pjp controller方法的信息对象
     * @return
     * @throws Throwable
     */
    @Around("execution(* com.study.security.web.controller.UserController.*(..))") // 包围的方法，要有返回值
    public Object handleControllerMethod(ProceedingJoinPoint pjp) throws Throwable {

//        System.out.println("my aspect start");
        Object[] args = pjp.getArgs();

//        for (Object arg : args) {
//            System.out.println("arg is" + arg);
//        }

        long start = System.currentTimeMillis();
        Object object = pjp.proceed();

//        System.out.println("my aspect 耗时：" + (System.currentTimeMillis() - start));
//        System.out.println("my aspect end");

        return object;
    }

}
